/**
 * @param {string[]} words
 * @param {string} order
 * @return {boolean}
 */
 var isAlienSorted = function(words, order) {
  const orderMap = new Map(order.split('').map((e, i) => [e, i]));
  const judge = (a, b) => {
      for(let i = 0; i < Math.min(a.length, b.length); i++) {
          if(orderMap.get(a[i]) > orderMap.get(b[i])) {
              return false
          } else if(orderMap.get(a[i]) < orderMap.get(b[i])) {
              return true;
          }
      }
      return a.length <= b.length;
  }
  for(let i = 0; i < words.length - 1; i++) {
      if(!judge(words[i], words[i + 1])) return false;
  }
  return true;
};